package com.ruoyi.medicine.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.medicine.domain.HisMedicineOrder;
import com.ruoyi.medicine.domain.HisMedicineOrderCheck;
import com.ruoyi.medicine.mapper.HisMedicineOrderCheckMapper;
import com.ruoyi.medicine.mapper.HisMedicineOrderMapper;
import com.ruoyi.medicine.service.IHisMedicineOrderCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 检验记录信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-03
 */
@Service
public class HisMedicineOrderCheckServiceImpl implements IHisMedicineOrderCheckService 
{
    @Autowired
    private HisMedicineOrderCheckMapper hisMedicineOrderCheckMapper;
    @Autowired
    private HisMedicineOrderMapper orderMapper;

    /**
     * 查询检验记录信息
     * 
     * @param checkId 检验记录信息主键
     * @return 检验记录信息
     */
    @Override
    public HisMedicineOrderCheck selectHisMedicineOrderCheckByCheckId(Long checkId)
    {
        return hisMedicineOrderCheckMapper.selectHisMedicineOrderCheckByCheckId(checkId);
    }

    /**
     * 查询检验记录信息列表
     * 
     * @param hisMedicineOrderCheck 检验记录信息
     * @return 检验记录信息
     */
    @Override
    public List<HisMedicineOrderCheck> selectHisMedicineOrderCheckList(HisMedicineOrderCheck hisMedicineOrderCheck)
    {
        return hisMedicineOrderCheckMapper.selectHisMedicineOrderCheckList(hisMedicineOrderCheck);
    }

    /**
     * 新增检验记录信息
     * 
     * @param hisMedicineOrderCheck 检验记录信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertHisMedicineOrderCheck(HisMedicineOrderCheck hisMedicineOrderCheck)
    {
        hisMedicineOrderCheck.setCreateTime(DateUtils.getNowDate());
        //1新增检查记录
        int i = hisMedicineOrderCheckMapper.insertHisMedicineOrderCheck(hisMedicineOrderCheck);
        //2修改采购单状态
        HisMedicineOrder order = new HisMedicineOrder();
        order.setOrderId(hisMedicineOrderCheck.getOrderId());
        order.setOrderStatus(hisMedicineOrderCheck.getCheckResult());
        order.setUpdateTime(DateUtils.getNowDate());
        orderMapper.updateHisMedicineOrder(order);
        return i;
    }

    /**
     * 修改检验记录信息
     * 
     * @param hisMedicineOrderCheck 检验记录信息
     * @return 结果
     */
    @Override
    public int updateHisMedicineOrderCheck(HisMedicineOrderCheck hisMedicineOrderCheck)
    {
        hisMedicineOrderCheck.setUpdateTime(DateUtils.getNowDate());
        return hisMedicineOrderCheckMapper.updateHisMedicineOrderCheck(hisMedicineOrderCheck);
    }

    /**
     * 批量删除检验记录信息
     * 
     * @param checkIds 需要删除的检验记录信息主键
     * @return 结果
     */
    @Override
    public int deleteHisMedicineOrderCheckByCheckIds(Long[] checkIds)
    {
        return hisMedicineOrderCheckMapper.deleteHisMedicineOrderCheckByCheckIds(checkIds);
    }

    /**
     * 删除检验记录信息信息
     * 
     * @param checkId 检验记录信息主键
     * @return 结果
     */
    @Override
    public int deleteHisMedicineOrderCheckByCheckId(Long checkId)
    {
        return hisMedicineOrderCheckMapper.deleteHisMedicineOrderCheckByCheckId(checkId);
    }
}
